package com.rocching.easychat.core;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import androidx.core.app.NavUtils;
import androidx.fragment.app.FragmentTransaction;

import com.rocching.easychat.R;

import io.rong.imkit.activity.RongBaseActivity;
import io.rong.imkit.utils.RouteUtils;

public class SubConversationListActivity extends RongBaseActivity {
    private final String TAG = SubConversationListActivity.class.getName();
    private boolean needRefresh = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getIntent() != null) {
            String title = getIntent().getStringExtra(RouteUtils.TITLE);
            mTitleBar.setTitle(title);
        } else {
            mTitleBar.setTitle(getString(R.string.msg_system_tip));
        }
        mTitleBar.setRightVisible(false);

        setContentView(R.layout.activity_subconversation_list);

        SubConversationListFragmentEx fragment = new SubConversationListFragmentEx();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.sub_conversation_layout, fragment);
        transaction.commit();
    }

    public void setNeedRefresh(boolean refresh) {
        this.needRefresh = refresh;
    }

    @Override
    public void onBackPressed() {
        if (needRefresh) {
            Intent intent = new Intent();
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra("needRefresh", needRefresh);
            this.setResult(RESULT_OK, intent);
        }
        finish();
    }
}
